<template>
  <div class="login-page">
    <LoginForm @login="handleLogin" />
     

  </div>
</template>

<script setup>
import LoginForm from "@/components/login/LoginForm.vue";
import LoginApi from "@/api/login/LoginApi";
import useUserStore from "@/store/modules/userStore";
import {useRouter} from "vue-router";
let router=useRouter()
let userStore=useUserStore()

function   handleLogin(formData) {
      console.log("登录数据:", formData);
      LoginApi.login({
        account: formData.account,
        password: formData.password,
      }).then((res) => {
      
        if(res.code==200){
          userStore.setUserInfo(res.data.data)
          userStore.setToken(res.data.token)
   
          //先存token 再跳路由 若不存token 则在路由拦截中被重定向到登录页
          router.push({
            path:"/home"
          })
        }
      });

      // 在这里可以添加实际的登录逻辑，例如调用 API
      // alert(`欢迎回来，${formData.username}！`);
    }
</script>

<style scoped>
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #6e8efb, #a777e3);
  color: #fff;
}
</style>